// 格式化日期为 YYYY-MM-DD 格式
export const formatDate = (date = new Date()) => {
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，需 +1
	const day = String(date.getDate()).padStart(2, '0');
	return `${year}-${month}-${day}`;
};

// 格式化日期时间函数 (示例: 2025-03-08 09:00)
const formatDateTime = (date) => {
	const y = date.getFullYear();
	const m = String(date.getMonth() + 1).padStart(2, '0');
	const d = String(date.getDate()).padStart(2, '0');
	const hh = String(date.getHours()).padStart(2, '0');
	const mm = String(date.getMinutes()).padStart(2, '0');
	return `${y}-${m}-${d} ${hh}:${mm}`;
};

export const getCurrentWeekRange = () => {
	const today = new Date();
	const dayOfWeek = today.getDay(); // 0（周日）到 6（周六）

	// 计算本周一的日期
	const monday = new Date(today);
	monday.setDate(today.getDate() - (dayOfWeek === 0 ? 6 : dayOfWeek - 1));

	// 计算本周日的日期
	const sunday = new Date(monday);
	sunday.setDate(monday.getDate() + 6);

	return formatDate(monday) + " 至 " + formatDate(sunday);
};

// 获取今天到下个月的同一天的日期范围
export const getCurrentMonthRange = () => {
    const today = new Date();
    const currentYear = today.getFullYear();
    const currentMonth = today.getMonth(); // 0（一月）到 11（十二月）

    // 本月第一天
    const firstDay = new Date(currentYear, currentMonth, 1);

    // 本月最后一天（下个月的第 0 天即为本月的最后一天）
    const lastDay = new Date(currentYear, currentMonth + 1, 0);

    return formatDate(firstDay) + " 至 " + formatDate(lastDay);
};